export const GET_RECOMMEND_LIST = "GET_RECOMMEND_LIST";
export const GET_RECOMMEND_LIST_SUCCESS = "GET_RECOMMEND_LIST_SUCCESS";
export const GET_RECOMMEND_LIST_FAIL = "GET_RECOMMEND_LIST_FAIL";

export interface IGetRecommendListAction {
  type: typeof GET_RECOMMEND_LIST;
  payload: number;
}

export interface IGetRecommendListSuccessAction {
  type: typeof GET_RECOMMEND_LIST_SUCCESS;
  payload: IRecommendListData;
}

export interface IGetRecommendListFailAction {
  type: typeof GET_RECOMMEND_LIST_FAIL;
  payload: number;
}

export const getRecommendList = (
  limit: number = 6
): IGetRecommendListAction => {
  return {
    type: GET_RECOMMEND_LIST,
    payload: limit,
  };
};

export interface IRecommendItem {
  alg: string;
  canDislike: boolean;
  copywriter: string;
  highQuality: boolean;
  id: string;
  name: string;
  picUrl: string;
  playCount: number;
  trackCount: number;
  trackNumberUpdateTime: number;
  type: number;
}

export interface IRecommendListData {
  category: number;
  code: number;
  hasTaste: boolean;
  result: IRecommendItem[];
}

export const getRecommendListSuccess = (data: IRecommendListData) => {
  return {
    type: GET_RECOMMEND_LIST_SUCCESS,
    payload: data,
  };
};

export const getRecommendListFail = () => {
  return {
    type: GET_RECOMMEND_LIST_FAIL,
    payload: 0,
  };
};

export type RecommendUnionType =
  | IGetRecommendListAction
  | IGetRecommendListSuccessAction
  | IGetRecommendListFailAction;
